package com.hhm.huo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhm.huo.entity.Result;
import com.hhm.huo.entity.Search;
import com.hhm.huo.entity.Student;
import com.hhm.huo.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 安安
 * @since 2022-05-30
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    IStudentService studentService;

    /**
     * 列表
     * @param search
     * @return
     */
    @RequestMapping("list")
    public Result list(@RequestBody Search search){
        // 分页
        Page<Student> page = new Page<>(search.getPageNum(), search.getPageSize());
        // 对象封装类
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        // 入学时间区间查询
        if (search.getDate1()!=null){
            wrapper.ge("in_date", search.getDate1());
        }
        if (search.getDate2()!=null){
            wrapper.le("in_date", search.getDate2());
        }
        // 调用方法，查询分页数据
        Page<Student> studentPage = studentService.page(page, wrapper);

        return new Result(studentPage);
    }

}
